package QQClient;

import java.io.File;
import java.io.FileInputStream;
import java.io.DataOutputStream;

public class FileSendThread extends Thread {

	public FileSendThread(int userQQ,File file,DataOutputStream douts,int destQQ){
		this.douts=douts;
		this.file=file;
		this.destQQ=destQQ;
		this.userQQ=userQQ;
	}
	public void run(){
		try{
			String fileName=file.getName();
			byte[] temb=fileName.getBytes();

			FileInputStream fins=new FileInputStream(file);

			int fileLen=fins.available();
			byte[] fileData=new byte[fileLen];
			fins.read(fileData);
			douts.writeInt(temb.length+fileLen+9+4+1);
			douts.writeByte(5);
			douts.writeInt(destQQ);
			douts.writeInt(userQQ);
			douts.writeInt(temb.length);
			douts.write(temb);
			douts.write(fileData);
			douts.flush();

		}catch(Exception e){
			e.printStackTrace();
		 }
	}
	private int userQQ,destQQ;
	private File file;
	private DataOutputStream douts;
}
